const path = require('path');
const webpack = require('webpack');
const Mocha = require('mocha');

const mocha = new Mocha({
    timeout: '10000ms',
});

process.chdir(path.join(__dirname, 'template'));

const rimraf = require('rimraf');

rimraf('./dist', () => {
    const prodConfig = require('../../lib/webpack.prod.js');

    webpack(prodConfig, (err, stats) => {
        if (err) {
            console.error(err);
            process.exit(2);
        }
        console.log(stats.toString({
            colors: true,
            modules: false,
            children: false,
        }));

        console.log('Webpack build success, begin run test');

        mocha.addFile(path.join(__dirname, 'html-test.js'));

        mocha.run();
    });
})

